package com.zjl.htmltopdf;

import io.woo.htmltopdf.HtmlToPdf;
import io.woo.htmltopdf.HtmlToPdfObject;

public class PdfDemo {
    public static void main(String[] args) {
        htmlToPdf();
    }

    /**
     * 根据Html转换为pdf文件 支持多个str
     */
    private static void htmlToPdf() {
        String str = " <div id=\"view\" align=\"center\">\n" +
                "        <h1>Html To PDf 测试</h1>\n" +
                "        <h3>支持文字图片表格</h3>\n" +
                "\t\t\n" +
                "    </div>";
        String str2 = " <ul style=\"font-size:18px;color:red;list-style:none;\">\n" +
                "\t<li>苏州</li>\n" +
                "\t<li>南京</li>\n" +
                "\t<li>无锡</li>\n" +
                "</ul>\n" +
                "<br />\n" +
                "<table border=\"1\" style=\"align:center;\">\n" +
                "\t<tr>\n" +
                "\t\t<th>学科</th>\n" +
                "\t\t<th>成绩</th>\n" +
                "\t</tr>\n" +
                "\t<tr>\n" +
                "\t\t<td>数学</td>\n" +
                "\t\t<td>100</td>\n" +
                "\t</tr>\n" +
                "\t<tr>\n" +
                "\t\t<td>语文</td>\n" +
                "\t\t<td>93</td>\n" +
                "\t</tr>\n" +
                "\t<tr>\n" +
                "\t\t<td>物理</td>\n" +
                "\t\t<td>80</td>\n" +
                "\t</tr>\n" +
                "</table>";
        HtmlToPdf.create().object(HtmlToPdfObject.forHtml(str).defaultEncoding("utf8"))
                .object(HtmlToPdfObject.forHtml(str2).defaultEncoding("utf8")).convert("D:\\Test\\htmltest.pdf");
    }

    /**
     * 根据url转换为pdf文件 支持多个url html和url可以混合使用
     */
    private static void urlToPdf() {
        HtmlToPdf.create()
                .object(HtmlToPdfObject.forUrl("https://blog.51cto.com/itShareArea/6182341"))
                .object(HtmlToPdfObject.forUrl("https://blog.51cto.com/itShareArea/6179253"))
                .convert("D:\\Test\\url-html.pdf");
    }
}